from appium import webdriver
from appium.webdriver.common.mobileby import MobileBy

from APPauto.test_APPauto_practice.test_enterprise_wechat_app.po_add_member.package.address_book_package import \
    AddressBookPackage


class MainPackage:
    def __init__(self):
        desired_caps = {}
        desired_caps['platformName'] = 'Android'
        desired_caps['platformVersion'] = '6.0'
        desired_caps['deviceName'] = '127.0.0.1:7555'  # adb connect 127.0.0.1:7555    adb devices
        desired_caps['appPackage'] = 'com.tencent.wework'
        desired_caps['appActivity'] = '.launch.LaunchSplashActivity'
        desired_caps['noReset'] = 'true'  # APP不进行再次设置，默认FALSE（每次都会初始化APP）,会保留一些设置，缓存信息等，如：欢迎页没有了，也可绕开登录
        desired_caps['dontStopAppOnReset'] = 'true'  # 直接在APP启动的情况下操作，不重新打开APP，与drive.back()配合使用
        desired_caps['skipDeviceInitialization'] = 'true'  # 跳过安装、权限设置等操作
        desired_caps['unicodekeyBoard'] = 'true'  # 允许输入中文
        desired_caps['resetkeyBoard'] = 'true'  # 允许输入中文
        desired_caps['settings[waitForIdleTimeout]'] = 1  # 控制动态页面的等待时长
        # 初始化driver
        self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
        self.driver.implicitly_wait(10)

    def get_address_book_package(self):
        # 进入通讯录页面
        self.driver.find_element(MobileBy.XPATH,"//*[@text='通讯录']").click()
        return AddressBookPackage(self.driver)

